<style lang="less">
@import "../../styles/common.less";
</style>

<template>
  <div>
    <Form :label-width="100">
      <Card>
        <p slot="title">团长分润设置</p>
        <Row type="flex" justify="start">
          <Col span="12">
            <FormItem label="分润类型">
              <RadioGroup v-model="application.profitType">
                    <Radio label="1">
                      <span>按订单金额比例</span>
                    </Radio>
                    <Radio label="2">
                      <span>每件固定金额</span>
                    </Radio>
                  </RadioGroup>
            </FormItem>
          </Col>
        </Row>
        <Row type="flex" justify="start" v-if="application.profitType=='1'">
          <Col span="12">
            <FormItem label="分润比例">
              <InputNumber
                :min="0"
                v-model="application.rating"
                style="width:150px"
              />&nbsp;&nbsp;&nbsp;%
            </FormItem>
          </Col>
        </Row>
        <Row type="flex" justify="start" v-if="application.profitType=='2'">
          <Col span="12">
            <FormItem label="金额(元)">
              <InputNumber
                :min="0"
                v-model="application.amount"
                style="width:150px"
              />
            </FormItem>
          </Col>
        </Row>
        <Button @click="updateApplication" type="primary" size="large" :loading="loading">保存</Button>
      </Card>
    </Form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      loading: false,
      application: {
        profitType: '1',
        rating: 5,
        amount: 5.00
      }
    };
  },
  methods: {
    updateApplication() {
      this.loading = true;
      this.$http
        .post(
          "/admin/changeProfitMerchant",
          this.common.request(this.application)
        )
        .then(
          response => {
            this.loading = false;
            if (response.data.body.status.statusCode == 0) {
              this.$Notice.success({
                title: "成功",
                desc: "团长分润设置已保存",
                duration: 2
              });
            } else {
              this.$Message.error(response.data.body.status.errorDesc);
            }
          },
          response => {
            this.loading = false;
          }
        );
    },
    getApplication() {
      this.$http
        .post("/admin/inquiryProfitMerchant", this.common.request({}))
        .then(
          response => {
            if (response.data.body.status.statusCode == 0 && response.data.body.data) {
              this.application = response.data.body.data;
            }
          },
          response => {}
        );
    }
  },
  created() {},
  mounted() {
    this.getApplication();
  },
  destroyed() {}
};
</script>
<style>

</style>
